const express = require("express");
const qs = require("querystring");
const app = express();

app.use((req, res, next) => {
  console.log("这是自定义中间件函数");
  let str = "";
  req.on("data", (chunk) => {
    str += chunk;
  });
  req.on("end", () => {
    const body = qs.parse(str);
    console.log(body);
    req.body = body;
    next()
  });
});

app.post("/", (req, res) => {
  res.send("hello ! 我是" + req.body.name + "今年" + req.body.age + "岁");
});

app.listen(80, () => {
  console.log("http://127.0.0.1");
});
